﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Manage/TeacherMasterPage.master" AutoEventWireup="true" CodeFile="students.aspx.cs" Inherits="Manage_students" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<mce:style type="text/css"><!--  
       
        a.addfile   
        {   
         background-image: url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif);   
         background-repeat: no-repeat;   
         background-position: -823px -17px;   
         display: block;   
         float: left;   
         height: 25px;   
         margin-top: -1px;   
         position: relative;   
         text-decoration: none;   
         top: 0pt;   
         width: 65px;   
         overflow:hidden;   
        }   
        a.addfile:hover   
        {   
         background-position: -911px -17px;   
        }   
        input.addfile   
        {   
         cursor: pointer !important;   
         height: 25px;   
         left: -6px;   
         filter: alpha(opacity=0);   
         position: absolute;   
         width: 0px;   
         z-index: -1;   
        }   
          
    --></mce:style>
<style type="text/css" mce_bogus="1">   
        a.addfile   
        {   
         background-image: url(http://p.mail.163.com/js31style/lib/0703131650/163blue/f1.gif);   
         background-repeat: no-repeat;   
         background-position: -823px -17px;   
         display: block;   
         float: left;   
         height: 25px;   
         margin-top: -1px;   
         position: relative;   
         text-decoration: none;   
         top: 0pt;   
         width: 65px;   
         overflow:hidden;   
        }   
        a.addfile:hover   
        {   
         background-position: -911px -17px;   
        }   
        input.addfile   
        {   
         cursor: pointer !important;   
         height: 25px;   
         left: -6px;   
         filter: alpha(opacity=0);   
         position: absolute;   
         width: 0px;   
         z-index: -100;   
        }   
        </style>   
<script type="text/javascript" src="../js/jquery/jquery.ajaxfileupload.js"></script>
<script>
    $(function () {
        $("#dg tbody tr").hoverIntent(
            function () { $(this).children().css("background-color", "#F2F4F6"); },
            function () { $(this).children().css("background-color", "#FFFFFF"); }
        );
        $('#BtnAdd').click(function (e) {
            $('#Add-modal-content').modal({
                opacity: 55, zIndex: 10,
                onOpen: function (dialog) {
                    dialog.overlay.fadeIn('fast', function () {
                        dialog.data.hide();
                        dialog.container.fadeIn('fast', function () {
                            dialog.data.show(); //slideDown('slow');
                        });
                    });
                }
            });
            return false;
        });
        $("#BtnImport").click(function (e) {
            $('#Import-modal-content').modal({
                opacity: 55, zIndex: 10,
                onOpen: function (dialog) {
                    dialog.overlay.fadeIn('fast', function () {
                        dialog.data.hide();
                        dialog.container.fadeIn('fast', function () {
                            dialog.data.show(); //slideDown('slow');
                            //$("##simplemodal-container").css("height","220px");
                        });
                    });
                }
            });
            return false;
        });
        $("#BtnDel").click(function (e) {
            confirm("<%= Resources.labels.ConfirmDelete %>", function () {
                //window.location.href = window.location.href;
                var chk = "";
                $("input[name=chkStudent]").each(function () {
                    //$(this).attr("checked", !this.checked);
                    if ($(this).attr("checked")) {
                        chk += $(this).val() + ",";
                    }
                });
                if (chk != "") {
                    var array = chk.split(',');
                    for (var i = 0; i < array.length; i++) {
                        if (array[i] != "") {
                            var ss = delStu(chk);
                            if (ss) {
                                rowHide(chk);
                            }
                        }
                    }
                    //alert("<%= Resources.labels.Del_ok %>");
                    //window.location.href = window.location.href;
                    $("#statusDel").html("&nbsp;<img src='../images/ok.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_ok%>").css("color", "#066606").show();
                    window.setTimeout(refresh, 2000);

                } else {
                    $("#statusDel").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.PleaseChkStudent%>").css("color", "#FF0000").show();
                }
            });
        });
        $(".btn").mouseover(function () { $(this).css("color", "#FF0000"); }).mouseout(function () { $(this).css("color", "#555"); });
    });
    function refresh() {
        location.reload();
        //window.location.href = window.location.href;
    }
</script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table class="grid" border="0" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th><b><%= Resources.labels.StudentList%></b></th>
            </tr>
        </thead>
<tr><td align=left> 
    <a href='#' id='BtnAdd' class="button"><%= Resources.labels.Add_Student%></a>
    <a href='#' id='BtnImport' class="button"><%= Resources.labels.Import_list%></a>
    <a href='#' id='BtnDel' class="button"><%= Resources.labels.Delete_Chk%></a>
    </td></tr>
<tr>
<td>
    <table id="dg" class="grid" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th width=5%><%= Resources.labels.select%></th>
                <th width=10%><%= Resources.labels.stuNumber%></th>
                <th width=10%><%= Resources.labels.stuName%></th>
                <th width=10%><%= Resources.labels.password%></th>
                <th width=15%><%= Resources.labels.email%></th>
                <th><%= Resources.labels.Department%></th>
                <th width=15%><%= Resources.labels.Operate%></th>
            </tr>
        </thead>
        <tbody>
        <asp:Repeater ID="rp" runat="server" EnableViewState=false>
        <ItemTemplate>
            <tr id="tr<%# Eval("StudentID")%>">
                <td><input id="chk<%# Eval("StudentID")%>" name="chkStudent" value='<%# Eval("StudentID")%>' type="checkbox" /></td>
                <td><%# Eval("StudentNumber")%></td>
                <td><%# Eval("StudentName")%></td>
                <td><%# Eval("StudentPassword")%></td>
                <td><%# Eval("StudentEmail")%></td>
                <td><%# getDepart(Eval("DepartmentID").ToString().Trim())%></td>
                <td>
                <a href="#" class="uiButton" onclick="EditStu('<%# Eval("StudentID")%>','<%# Eval("StudentNumber")%>','<%# Eval("StudentName")%>','<%# Eval("StudentPassword")%>','<%# Eval("StudentEmail")%>','<%# Eval("DepartmentID")%>')"><%= Resources.labels.Edit%></a>&nbsp;
                <a href="#" class="uiButton" onclick='delSingleStu(<%# Eval("StudentID")%>)'><%= Resources.labels.Delete%></a></td>
            </tr>
        </ItemTemplate>
        </asp:Repeater>
        </tbody>
    	<tfoot>
    	    <tr>
    	        <td colspan=7 align=left>
    	            <webdiyer:aspnetpager id="AspNetPager1" runat="server" 
    	            EnableViewState="True"
    	            horizontalalign="Center" 
    	            PagingButtonSpacing="8px" 
                    showcustominfosection="Left" 
                    urlpaging="false" width="100%" 
                    ImagePath="~/images" 
                    NumericButtonType="Text" 
                    ButtonImageExtension="gif" 
                    ButtonImageNameExtension="n" 
                    DisabledButtonImageNameExtension="g" 
                    ShowNavigationToolTip="true" 
                    FirstPageText="<<" 
                    LastPageText=">>" NextPageText=">" PageSize="12" 
                    PrevPageText="<" SubmitButtonText="Go" 
                        onpagechanged="AspNetPager1_PageChanged"></webdiyer:aspnetpager>
    	        </td>
    	    </tr>
            <tr>
            <td colspan=7 align=left>
                <%= Resources.labels.search%>:
                <asp:DropDownList ID="departddl" runat="server"></asp:DropDownList>
                <asp:TextBox ID="keywordTb" runat="server" Text="" ></asp:TextBox>
                <asp:Button ID="btnSearch" CssClass="button" runat="server" Text="查询" onclick="btnSearch_Click" />
            </td>
            </tr>
    	</tfoot>
    </table>
</td>

</tr>
</table>


<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
    <table class="grid" border="0" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th><%= Resources.labels.count%>：<%= Resources.labels.total%> <asp:Label ID="LibStuCount" runat="server" Text="0"></asp:Label> <%= Resources.labels.Student%> </th>
            </tr>
        </thead>
    </table>
</td>
</tr>
</table>

<div id="Add-modal-content">
    <div class="modal-div"><span><%= Resources.labels.stuNumber%>：</span><input id="stuNum" type="text" />(<%= Resources.labels.isRequiredField%>)</div>
    <div class="modal-div"><span><%= Resources.labels.stuName%>：</span><input id="stuName" type="text" />(<%= Resources.labels.isRequiredField%>)</div>
    <div class="modal-div"><span><%= Resources.labels.password%>：</span><input id="stuPas" type="text" />(<%= Resources.labels.isRequiredField%>)</div>
    <div class="modal-div"><span><%= Resources.labels.repassword%>：</span><input id="rePas" type="text" />(<%= Resources.labels.isRequiredField%>)</div>
    <div class="modal-div"><span><%= Resources.labels.email%>：</span><input id="stuEmail" type="text" /></div>
    <div class="modal-div"><span><%= Resources.labels.Department%>：</span><asp:DropDownList ID="departddl2" runat="server"></asp:DropDownList></div>
    <div class="modal-div">
    <span style="float:left;margin-left:20px;">
    <input id="Button3" type="button" class="button" onclick="addNew()" value="<%= Resources.labels.add%>" />
    <input id="btnCancle" type="button" class="button" value="<%= Resources.labels.cancel%>" onclick="Cancle()" />
    </span>
    <span id="statusAdd" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
    <img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" /><%= Resources.labels.PleaseWaiting%>
    </span>
    </div>
</div>
<div id='confirm'>
	<div class='header'><span><%= Resources.labels.warning%></span></div>
	<div class='message'></div>
	<span id="statusDel" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
    <img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" /><%= Resources.labels.PleaseWaiting%>
    </span>
	<div class='buttons'>
		<div class='no simplemodal-close'><%= Resources.labels.cancel%></div>
		<div class='yes'><%= Resources.labels.Delete%></div>
		
	</div>
</div>
<div id="Edit-modal-content">
    <div class="modal-div"><%= Resources.labels.stuNumber%>：<input id="EditstuNum" type="text" />(<%= Resources.labels.isRequiredField%>)</div>
    <div class="modal-div"><%= Resources.labels.stuName%>：<input id="EditstuName" type="text" />(<%= Resources.labels.isRequiredField%>)</div>
    <div class="modal-div"><%= Resources.labels.password%>：<input id="EditstuPas" type="text" />(<%= Resources.labels.isRequiredField%>)</div>
    <div class="modal-div"><%= Resources.labels.repassword%>：<input id="EditrePas" type="text" />(<%= Resources.labels.isRequiredField%>)</div>
    <div class="modal-div"><%= Resources.labels.email%>：<input id="EditstuEmail" type="text" /></div>
    <div class="modal-div"><%= Resources.labels.Department%>：<asp:DropDownList ID="Editdepartddl2" runat="server"></asp:DropDownList>
                            <input id="EditstuId" type="hidden" value="" />
                            </div>
    <div class="modal-div">
    <span style="float:left;margin-left:20px;">
    <input id="Button4" type="button" class="button" onclick="btnEdit()" value="<%= Resources.labels.Edit%>" />
    <input id="Button5" type="button" class="button" value="<%= Resources.labels.cancel%>" onclick="Cancle()" />
    </span>
    <span id="statusEdit" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
    <img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" /><%= Resources.labels.PleaseWaiting%>
    </span>
    </div>
</div>
<div id="Import-modal-content">
    <%= Resources.labels.Import_list%><%= Resources.labels.Student%>
    
    <div>
    <asp:DropDownList ID="departddl3" runat="server"></asp:DropDownList>
    <br /><br />
    <asp:FileUpload ID="fup" runat="server" CssClass="addfile" size="1" title="Browse" style="display:none;" />
    <input type="button" class="button" onclick="HandleFileButtonClick();" value="Browse">
    <span  id="statusImport" class="status1" style="display:none;font-size:0.8em;padding-top:5px;"><img src='../images/ajax-loader.gif'  border=0 style="vertical-align:middle;" /> <%= Resources.labels.PleaseWaiting%></span>
    <input id="hidfup" type="hidden" value="" />
    </div>
    <br />
    <div style="font-size:0.7em;">(<%= Resources.labels.onlyExcel%>)

    <a href="../template/student.xls" class="button"><%= Resources.labels.DownTemplate%></a>
    

<script>
function addNew() {
    var stuNum = $("#stuNum").val();
    var stuName = $("#stuName").val();
    var stuPas = $("#stuPas").val();
    var rePas = $("#rePas").val();
    var stuEmail = $("#stuEmail").val();
    var stuDept = $("#<%=departddl2.ClientID%>").val();
    if (stuNum == "") { alert("<%= Resources.labels.enterValid%><%= Resources.labels.stuNumber%>"); return false; }
    if (stuName == "") { alert("<%= Resources.labels.enterValid%><%= Resources.labels.stuName%>"); return false; }
    if (stuPas == "") { alert("<%= Resources.labels.enterValid%><%= Resources.labels.password%>"); return false; }
    if (stuPas != rePas) { alert("<%= Resources.labels.password_re_no%>"); return false; }
    $.ajax({
        type: "POST",
        cache: false,
        url: "Service/addStudent.aspx",
        data: "stuNum=" + stuNum + "&stuName=" + stuName + "&stuPas=" + stuPas + "&stuEmail=" + stuEmail + "&stuDept=" + stuDept,
        beforeSend: function() {
            $(".status").show();
            $("#btnCancle").attr('disabled', true);
            $("#btnAdd").attr('disabled', true);
        },
        success: function(msg) {
            if (msg == "1") {
                if (confirm("<%= Resources.labels.Add_Ok_Continue%>")) {
                    $("#stuNum").val("");
                    $("#stuName").val("");
                    $("#stuPas").val("");
                    $("#rePas").val("");
                    $("#stuEmail").val("");
                } else {
                    $(".status").hide();
                    $("#btnCancle").attr('disabled', false);
                    $("#btnAdd").attr('disabled', false);
                    $.modal.close();
                    window.location.href = location.href;
                }
            } else {
                alert("<%= Resources.labels.Add_Fail%>");
            }

        },
        error: function(msg) {
            $(".status").hide();
            $("#btnCancle").attr('disabled', false);
            $("#btnAdd").attr('disabled', false);
            alert("<%= Resources.labels.Add_Err%>");
        }
    });
}
function Cancle() {
    $.modal.close();
}
function confirm(message, callback) {
    $('#confirm').modal({
        closeHTML: "<a href='#' title='<%= Resources.labels.btnclose%>' class='modal-close'>x</a>",
        //position: ["20%", ],
        overlayId: 'confirm-overlay',
        containerId: 'confirm-container',
        onShow: function(dialog) {
            var modal = this;
            $('.message', dialog.data[0]).append(message);
            // if the user clicks "yes"
            $('.yes', dialog.data[0]).click(function() {
                // call the callback
                if ($.isFunction(callback)) {
                    callback.apply();
                }
                // close the dialog
                //modal.close(); // or $.modal.close();
            });
        }
    });
}
function EditStu(id, stuNum, stuName, stuPas, stuEmail, stuDept) {
    $('#Edit-modal-content').modal({
        opacity: 55, zIndex: 10,
        onOpen: function(dialog) {
            dialog.overlay.fadeIn('fast', function() {
                //赋值
                $("#EditstuId").val(id);
                $("#EditstuNum").val(stuNum);
                $("#EditstuName").val(stuName);
                $("#EditstuPas").val(stuPas);
                $("#EditrePas").val("");
                $("#EditstuEmail").val(stuEmail);
                $("#<%=Editdepartddl2.ClientID %>").val(stuDept);

                dialog.data.hide();
                dialog.container.fadeIn('fast', function() {
                    dialog.data.show(); //slideDown('slow');
                });
            });
        }
    });
    return false;
}
function btnEdit() {
    var stuId = $("#EditstuId").val();
    var stuNum = $("#EditstuNum").val();
    var stuName = $("#EditstuName").val();
    var stuPas = $("#EditstuPas").val();
    var rePas = $("#EditrePas").val();
    var stuEmail = $("#EditstuEmail").val();
    var stuDept = $("#<%=Editdepartddl2.ClientID%>").val();
    if (stuNum == "") { alert("<%= Resources.labels.enterValid%><%= Resources.labels.stuNumber%>"); return false; }
    if (stuName == "") { alert("<%= Resources.labels.enterValid%><%= Resources.labels.stuName%>"); return false; }
    if (stuPas == "") { alert("<%= Resources.labels.enterValid%><%= Resources.labels.password%>"); return false; }
    if (stuPas != rePas) { alert("<%= Resources.labels.password_re_no%>"); return false; }
    $.ajax({
        type: "POST",
        cache: false,
        url: "Service/EditStudent.aspx",
        data: "stuId=" + stuId + "&stuNum=" + stuNum + "&stuName=" + stuName + "&stuPas=" + stuPas + "&stuEmail=" + stuEmail + "&stuDept=" + stuDept,
        beforeSend: function() {
            $(".status").show();
            $("#Button4").attr('disabled', true);
            $("#Button5").attr('disabled', true);
        },
        success: function(msg) {
            if (msg == "1") {
                $.modal.close();
                window.location.href = location.href;
            } else {
                alert("<%= Resources.labels.Edit_Fail%>");
            }

        },
        error: function(msg) {
            $(".status").hide();
            $("#Button4").attr('disabled', false);
            $("#Button5").attr('disabled', false);
            alert("<%= Resources.labels.Edit_Err%>");
        }
    });

}

function delStu(id) {
    var result = false;
    $.ajax({
        type: "POST",async:false,
        cache: false,
        url: "Service/delStudent.aspx",
        data: "id=" + id,
        beforeSend: function () {
            $(".status").show();
        },
        success: function (msg) {
            if (msg == "1") { result = true; }
            else { result = false; }
        },
        error: function (msg) {
            result = false;
        }
    });
    return result;
}
function rowHide(id) {$("#tr" + id).hide(); }
function delSingleStu(id) {
    confirm("<%= Resources.labels.ConfirmDelete%>", function () {
        var ss = delStu(id);
        if (ss) {
            $("#statusDel").html("&nbsp;<img src='../images/ok.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_ok%>").css("color", "#066606").show();
            window.setTimeout("rowHide(" + id + ")", 2000);
            //$.modal.close();
        } else {
            $("#statusDel").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.PleaseChkStudent%>").css("color", "#FF0000").show();
        }
    });
}

function HandleFileButtonClick() {
    document.getElementById("<%=fup. ClientID %>").click();
}

$(function(){
    $('#<%=fup. ClientID %>').change(function () {
        upload();
    });
});

function upload() {
    
    var result = false;
    var filepath = $("#<%=fup. ClientID %>").val();
    var extStart = filepath.lastIndexOf(".");
    var ext = filepath.substring(extStart, filepath.length).toUpperCase();
    if (ext == ".XLS") {
        result = true;
    }
    if (!result) {
        alert("<%= Resources.labels.onlyExcel%>"); return false;
    }
    $.ajaxFileUpload({
        url: '../ajaxUpload.aspx?random=' + Math.random(),
        secureuri: false,
        fileElementId: '<%=fup. ClientID %>',
        dataType: 'text',
        success: function (msg, status) {
            if (msg != '') {
                $('#hidfup').val(msg);
                ImportStu();
            }
            else {
                alert("<%= Resources.labels.mistakesAgain%>");
            }
        },
        error: function (msg, status, e) {
            alert("<%= Resources.labels.mistakesAgain%>" + e); $('#hidfup').val(""); $("#statusImport").hide();
        }

    });
    $('#<%=fup. ClientID %>').change(function () {
        upload();
    });
}

function ImportStu() {

    var xls = $("#hidfup").val();
    var dept = $("#<%=departddl3.ClientID%>").val();
    if (xls == "") { alert("<%= Resources.labels.mistakesAgain%>"); return false; }
    $.ajax({
        type: "POST", cache: false,
        url: "Service/importstu.aspx",
        data: "dept=" + dept + "&filename=" + xls,
        beforeSend: function () {
            alert("daoru");
            $("#statusImport").css("display", "inline-block");
        },
        success: function (msg) {
            if (msg == "erro") { alert("<%= Resources.labels.Del_Fail%>"); $.modal.close(); }
            else {
                if (msg.split(',').length > 0) {
                    var tmp = "<%= Resources.labels.importstudent_Log%>";
                    tmp = tmp.replace("{0}", msg);
                    alert(tmp);
                } else {
                    alert("<%= Resources.labels.Import_ok%>");
                }
            }
            $.modal.close(); window.location.href = window.location.href;
        }
    });

}
</script>

</asp:Content>




